<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <style>
    html,
    body {
      height: 100%;
    }

    .bnmap-msgBox h2 {
      background: #2F77FD;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #FFFFFF;
    }

    .tableClass {
      border: 1px solid #151515;
      width: 100%;
      height: 100%;
    }

    .tableClass td {
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #666666;
    }

    .td1 {
      background: rgba(47, 119, 253, 0.16);
    }

    .td2 {
      background: rgba(47, 119, 253, 0.08);
    }

    .td3 {
      background: rgba(47, 119, 253, 0.02);
    }

    .left-td {
      margin-left: 17px;
    }

    .right-td {
      margin-right: 17px;
    }

    .div1 {
      text-align: right;
      margin-right: 17px;
    }

    .div2 {
      margin-left: 17px;
    }
  </style>
  <link type="text/css" rel="stylesheet" href="../bjbn/bnmap.css">
  <script type="text/javascript" src="../mapjs/BNMap.min.js?appKey=null&appSecret=null"></script>
  <script type="text/javascript" src="../mapjs/mapTopic.js"></script>
</head>

<body>
  <div id="mapContent" style="width: 100%;height: 100%;background: #020F1A;"></div>
  <script>
    /**
     * 地图实例对象
     */
    var mapObj = null;
    /**
     * 地图初始化监听对象
     */
    var mapLoad = null;
    /**
     * 内置地图对象
     */
    var bnmap = null;
    /**
     * 距离测量工具
     */
    var distanceTool = null;
    /**
     * 地图标绘工具
     */
    var drawTool = null;
    /**
     * 地图标绘用到得临时图层
     */
    var tempLayer = null;
    /**
     * 默认展示图层
     */
    var layers = [];
    /**
     * 临时区域
     */
    var geometrys = [];
    /**
     * 需要加载的图层数据
     */
    var geometryExtent = [];
    /**
     * 是否开启绘画图层监听
     */
    var isOpenDrawMonitor = false;
    /**
     * 是否开启图形图层监听
     */
     var isOpenGeoMonitor = false;
    /**
     * 窗体工具
     */
    var bnWindows = null;
    /**
     * 窗体工具集合
     */
    var bnWindowsList = [];
    /**
     * 高亮图层
     */
    var lightLayer = null;
    /**
     * 未开始
     */
    var yellowLayer = [];
    /**
     * 进行中
     */
    var buleLayer = [];
    /**
     * 地图范围
    */
    var mapRange = null;
    let list = [];
    mapObj = new BNMap.BMap("mapContent", {
      center: [120.42882340100007, 30.237839784500053],
      "zoom": 15,
      "bearing": -27,
      "attribution": false,
      minZoom: 13, // set map's min zoom to 14
      maxZoom: 21  // set map's max zoom to 21
    }, topicObj, false)
    mapObj.on("load", function () {
      bnmap = mapObj._innerMap;
      bnmap._baseLayer.options.repeatWorld = false;
      // mapObj.setPointCenter();
      //初始化测距工具
      initMeasureTools();
      //初始化绘图工具
      initDrawTool();
      //初始化地图弹窗
      initInfoWindow();
      //加载临时图层
      //showGeoserver();
      //创建高亮图层
      lightLayer = new BNMap.VectorLayer('hightLight').addTo(bnmap);
      new BNMap.VectorLayer('readyLayer').addTo(bnmap);
      new BNMap.VectorLayer('doingLayer').addTo(bnmap);

      if (geometryExtent.length > 0) {
        addDrawLayer(geometryExtent);
      }
      if (yellowLayer.length > 0) {
        showGeoserverAll(yellowLayer, "未开始");
      }
      if (buleLayer.length > 0) {
        showGeoserverAll(buleLayer, "进行中");
      }
      setTimeout(function () {
        //指定显示要素图层
        showLayer(layers);
        getMonitor();
        if (window.parent['load']) {
          window.parent['load']();
        }
      }, 2500);

      mapRange = BNMap.turf.polygon([[
        [topicObj.baseMap[0].xmax, topicObj.baseMap[0].ymax],
        [topicObj.baseMap[0].xmax, topicObj.baseMap[0].ymin],
        [topicObj.baseMap[0].xmin, topicObj.baseMap[0].ymax],
        [topicObj.baseMap[0].xmin, topicObj.baseMap[0].ymin],
        [topicObj.baseMap[0].xmax, topicObj.baseMap[0].ymax]]]);
    })
    // mapLoad = BNMap.BFactory.Load('20034', {
    //   id: "mapContent",
    //   options: {
    //
    //   }
    // }, function (map) {
    //
    // });
    /**
     * 初始化测量工具
     * @returns
     */
    function initMeasureTools() {
      //距离测量工具
      distanceTool = new BNMap.DistanceTool({
        'symbol': {
          'lineColor': '#34495e',
          'lineWidth': 2
        },
        'vertexSymbol': {
          'markerType': 'ellipse',
          'markerFill': '#1bbc9b',
          'markerLineColor': '#000',
          'markerLineWidth': 3,
          'markerWidth': 10,
          'markerHeight': 10
        },

        'labelOptions': {
          'textSymbol': {
            'textFaceName': 'monospace',
            'textFill': '#fff',
            'textLineSpacing': 1,
            'textHorizontalAlignment': 'right',
            'textDx': 15,
            'markerLineColor': '#b4b3b3',
            'markerFill': '#000'
          },
          'boxStyle': {
            'padding': [6, 2],
            'symbol': {
              'markerType': 'square',
              'markerFill': '#000',
              'markerFillOpacity': 0.9,
              'markerLineColor': '#b4b3b3'
            }
          }
        },
        'clearButtonSymbol': [{
          'markerType': 'square',
          'markerFill': '#000',
          'markerLineColor': '#b4b3b3',
          'markerLineWidth': 2,
          'markerWidth': 15,
          'markerHeight': 15,
          'markerDx': 20
        }, {
          'markerType': 'x',
          'markerWidth': 10,
          'markerHeight': 10,
          'markerLineColor': '#fff',
          'markerDx': 20
        }],
        'language': 'zh-CN',
        'once': true
      }).addTo(bnmap);
      //默认禁用
      distanceTool.disable();
    }
    /**
     * 初始化地图标绘工具
     * @returns
     */
    function initDrawTool() {
      //绘制的临时图层
      if (tempLayer != null) {
        bnmap.removeLayer(tempLayer);
      }
      tempLayer = new BNMap.VectorLayer('drawVector').addTo(bnmap);
      //绘制工具，默认禁用
      drawTool = new BNMap.DrawTool({
        mode: 'Point'
      }).addTo(bnmap).disable();
      //绑定绘制完成事件
      drawTool.on('drawend', function (e) {
        e.geometry.options.groupid = (Math.random() + new Date().getTime()).toString(32).slice(0, 8);
        tempLayer.addGeometry(e.geometry);//将图形添加到地图上
        if (e.geometry.type == "Polygon") {
          drawTool.disable();
          setTimeout(function () {
            try {
              if (!checkLayer(e.geometry)) {
                let index1 = e.geometry.toGeoJSON();
                let coors = index1.geometry.coordinates;
                let collection = BNMap.turf.polygon(coors);
                if (BNMap.turf.turf.booleanContains(mapRange, collection)) {
                  window.parent["dialogOpen"](e.geometry);
                  e.geometry.on("click",function(eve){
                    if (isOpenGeoMonitor) {
                      window.parent["drawMonitor"](eve);
                    }
                  })
                } else {
                  tempLayer.removeGeometry(e.geometry);
                  window.parent["warnLog"]("超出范围，请重新绘画！");
                  drawPolygon();
                }
              } else {
                tempLayer.removeGeometry(e.geometry);
                window.parent["warnLog"]("与其他图层相交，请重新绘画！");
                drawPolygon();
              }
            } catch (error) {
              window.parent["warnLog"]("系统异常，请重新绘画！");
              drawPolygon();
            }
          }, 500);
        } else {
          window.parent["lineGeo"](e.geometry);
        }
      });
    }
    /**
     * 删除绘制图形
     * @pram geo-图形
     */
    function deletGeoString(geometry) {
      let jsonObj = JSON.parse(geometry);
      let layerList = tempLayer.getGeometries();
      for (let i = 0; i < layerList.length; i++) {
        if (layerList[i].options.groupid == jsonObj.options.groupid) {
          tempLayer.removeGeometry(layerList[i]);
        }
      }
    }
    /**
     * 添加绘制图层
     */
    function addDrawLayer(geoList) {
      let showLayer = tempLayer;
      //分两次循环添加要素的目的是为了让线路显示在区域上面
      for (let i = 0; i < geoList.length; i++) {
        if (geoList[i] != "") {
          let jsonObj = JSON.parse(geoList[i]);
          jsonObj.symbol = {
            'lineColor': "#C30a20",
            'lineWidth': 2,
            'polygonFill': "#E49D97"
          };
          if (jsonObj.feature.geometry.type == "Polygon") {
            let geo = new BNMap.Geometry.fromJSON(jsonObj);
            geo.on("click",function(eve){
              if (isOpenGeoMonitor) {
                window.parent["drawMonitor"](eve);
              }
            })
            showLayer.addGeometry(geo);
          }
        }
      }
      for (let i = 0; i < geoList.length; i++) {
        if (geoList[i] != "") {
          let jsonObj = JSON.parse(geoList[i]);
          jsonObj.symbol = {
            'lineColor': "#C30a20",
            'lineWidth': 2,
            'polygonFill': "#E49D97"
          };
          if (jsonObj.feature.geometry.type != "Polygon") {
            let geo = new BNMap.Geometry.fromJSON(jsonObj);
            showLayer.addGeometry(geo);
          }
        }
      }
    }
    /**
     * 回显绘制图层
     */
    function showDrawLayer(geoList) {
      let showLayer = tempLayer;
      for (let i = 0; i < geoList.length; i++) {
        let jsonObj = geoList[i];
        jsonObj.symbol = {
          'lineColor': "#C30a20",
          'lineWidth': 2,
          'polygonFill': "#E49D97"
        };
        let geo = new BNMap.Geometry.fromJSON(jsonObj);
        showLayer.addGeometry(geo);
      }
    }
    /**
     * 删除绘制图形
     * @pram geo-图形
     */
    function deletGeo(geometry) {
      tempLayer.removeGeometry(geometry);
    }
    /**
     * 禁止绘画
     */
    function stopDraw() {
      drawTool.disable();
    }
    /**
     * 清空绘制图形
     * @pram geo-图形
     */
    function deletAllGeo() {
      tempLayer.clear();
    }
    /**
     * 开始画图面
     */
    function drawPolygon() {
      var symbol = {
        'lineColor': "#C30a20",
        'lineWidth': 2,
        'polygonFill': "rgba(238, 21, 21, 0.2)"
      }
      drawTool.setSymbol(symbol);
      drawTool.setMode("Polygon").enable();
    }
    /**
     * 开始画线
     */
    function drawLine() {
      var symbol = {
        'lineColor': 'red',
        'lineWidth': 2,
      };
      drawTool.setSymbol(symbol);
      drawTool.setMode("FreeHandLineString").enable();
    }
    /**
     * 初始化地图弹窗
     * @returns
     */
    function initInfoWindow() {
      var options = {
        'title': '地图弹窗',
        'autoPan': false,
        'width': 320,
        'minHeight': 268,
        'height': 360,
        'single': false,
        //'dx': 5,
        //'dy': 5,
        'custom': false,
        'autoOpenOn': false,  //set to null if not to open window when clicking on map
        'autoCloseOn': 'click',
        'animation ': false
      };
      bnWindows = new BNMap.ui.InfoWindow(options);
      bnWindows.addTo(bnmap);
    }
    /**
     * 隐藏图层
     * @param ids - 图层编号组
     */
    function hideLayer(ids) {
      for (let i = 0; i < ids.length; i++) {
        let layer = bnmap.getLayer(ids[i]);
        layer.hide();
      }
    }
    /**
     * 显示图层
     * @param ids - 图层编号组
     */
    function showLayer(ids) {
      for (let i = 0; i < ids.length; i++) {
        let layer = bnmap.getLayer(ids[i]);
        // console.log(222)
        layer.show();
      }
    }
    /**
     * 开始测距
     */
    function distance() {
      distanceTool.enable();
    }
    /**
     * 放大
     */
    function enlarge() {
      let zoonCoordinate = bnmap.getCenter();
      let zoonNum = bnmap.getZoom() + 1;
      bnmap.setCenterAndZoom(zoonCoordinate, zoonNum);
    }
    /**
     * 缩小
     */
    function narrow() {
      let zoonCoordinate = bnmap.getCenter();
      let zoonNum = bnmap.getZoom() - 1;
      bnmap.setCenterAndZoom(zoonCoordinate, zoonNum);
    }
    /**
     * 指定显示图层
     */
    function showLayers(val, geo) {
      // console.log(val)
      layers = val;
      geometrys = geo;
    }

    /**
     * 查询所有要素并高亮显示
     */
    function highLight() {
      for (let i = 0; i < layers.length; i++) {
        let layer = bnmap.getLayer(layers[i]);
        let maps = mapObj.maps.baseElement;
        let layerName = "";
        for (let j = 0; j < maps.length; j++) {
          if (layer._id == maps[j].id) {
            layerName = maps[j].layer;
          }
        }
        BNMap.mapQuery(layerName, {
          "where": null,
          /*"workspace":"postgis",*/
          "geometry": null,
          "highLightSymbol": {
            point: {
              'markerType': 'ellipse',
              'markerFill': 'blue',
              'markerLineColor': 'white',
              'markerWidth': 20,
              'markerHeight': 20,
              'markerLineWidth': 2
            },
            polygon: {
              'lineColor': 'white',
              'lineWidth': 2,
              'polygonFill': 'blue',
            },
            polyline: {
              'lineColor': 'blue',
              'lineWidth': 2,
            }
          }

        }, bnmap, function (data) { });
      }
    }
    /**
     * 加载临时图层
     */
    function showGeoserver() {
      for (let i = 0; i < geometrys.length; i++) {
        tempLayer.addGeometry(geometrys[i]);
      }
    }
    /**
     * 创建图层并添加要素
     */
    function showGeoserverAll(geoList, type) {
      if (bnmap) {
        let showLayer = null;
        for (let i = 0; i < geoList.length; i++) {
          let jsonObj = JSON.parse(geoList[i]);
          if (type == "未开始") {
            let layer1 = bnmap.getLayer('readyLayer');
            if (layer1) {
              showLayer = layer1;
            } else {
              showLayer = new BNMap.VectorLayer('readyLayer').addTo(bnmap);
            }
            jsonObj.symbol = {
              'lineColor': "#2F77FD",
              'lineWidth': 2,
              'polygonFill': "rgba(47, 119, 253, 0.4)"
            };
          } else {
            let layer2 = bnmap.getLayer('doingLayer')
            if (layer2) {
              showLayer = layer2;
            } else {
              showLayer = new BNMap.VectorLayer('doingLayer').addTo(bnmap);
            }
            jsonObj.symbol = {
              'lineColor': "#F9B556",
              'lineWidth': 2,
              'polygonFill': "rgba(249, 181, 86, 0.4)"
            };
          }
          let geo = new BNMap.Geometry.fromJSON(jsonObj);
          showLayer.addGeometry(geo);
          geo.on('click', getDrawMonitor);
        }
      } else {
        if (type == "未开始") {
          yellowLayer = geoList;
        } else {
          buleLayer = geoList;
        }
      }

    }
    /**
     * 清除未开始和进行中tuceng
     */
    function clearColorLayer() {
      if (bnmap) {
        let layer1 = bnmap.getLayer('readyLayer');
        if (layer1) {
          layer1.clear();
        }
        let layer2 = bnmap.getLayer('doingLayer')
        if (layer2) {
          layer2.clear();
        }
      }
    }
    /**
     * 图层交叉验证
     */
    function checkLayer(geo) {
      let isPass = false;
      let layerList = tempLayer.getGeometries();
      let index1 = geo.toGeoJSON();
      let coors = index1.geometry.coordinates;
      let collection = BNMap.turf.polygon(coors, { name: 'poly' });
      for (let i = 0; i < layerList.length; i++) {
        if (layerList[i].options.groupid != geo.options.groupid && layerList[i].type == "Polygon") {
          let index2 = layerList[i].toGeoJSON();
          let coors2 = index2.geometry.coordinates;
          let collection2 = BNMap.turf.polygon(coors2, { name: 'poly' });
          if (BNMap.turf.turf.booleanOverlap(collection, collection2)) {
            isPass = true;
          }
          if (BNMap.turf.turf.booleanContains(collection, collection2) || BNMap.turf.turf.booleanContains(collection2, collection)) {
            isPass = true;
          }
        }
      }
      return isPass;
    }
    /**
     * 清除所有弹窗
     */
    function clearAllWindow() {
      for (let i = 0; i < bnWindowsList.length; i++) {
        const element = bnWindowsList[i];
        element.remove();
      }
      bnWindowsList = [];
    }
    /**
     * 施工区域显示弹窗
     */
     function showProjiectWindow(data,name) {
       if (!data && !name) {
         return;
       }
      clearAllWindow();
      var options = {
        'title': '地图弹窗',
        'autoPan': false,
        'width': 320,
        'minHeight': 268,
        'height': 360,
        'single': false,
        //'dx': 5,
        //'dy': 5,
        'custom': false,
        'autoOpenOn': false,  //set to null if not to open window when clicking on map
        'autoCloseOn': 'click',
        'animation ': false
      };
      let windowOne = new BNMap.ui.InfoWindow(options);
      windowOne.addTo(bnmap);
      windowOne.setTitle("施工区域");
      var html = "<table class='tableClass' cellspacing='0' align='center'>";
      html += "<tr>";
      html += "<td class='td1 right-td' ><div class='div1'>区域名称</div></td>";
      html += "<td class='td2 left-td'><div class='div2'style='word-break:break-all;'>" + name + "</div></td>";
      html += "</tr>";
      html += "</table>";
      windowOne.setContent(html);
      let geo = new BNMap.Geometry.fromJSON(JSON.parse(data));
      setTimeout(function () {
        windowOne.show(geo.getCenter());
        bnWindowsList.push(windowOne);
      }, 100);
      
    }
    /**
     * 显示弹窗
     */
    function showWindow(list) {
      clearAllWindow();
      for (let i = 0; i < list.length; i++) {
        var options = {
          'title': '地图弹窗',
          'autoPan': false,
          'width': 320,
          'minHeight': 268,
          'height': 360,
          'single': false,
          //'dx': 5,
          //'dy': 5,
          'custom': false,
          'autoOpenOn': false,  //set to null if not to open window when clicking on map
          'autoCloseOn': 'click',
          'animation ': false
        };
        let windowOne = new BNMap.ui.InfoWindow(options);
        windowOne.addTo(bnmap);
        windowOne.setTitle("停航详情");
        windowOne.setContent(createWindowTable(list[i]));
        let geo = new BNMap.Geometry.fromJSON(JSON.parse(list[i].geometry));
        windowOne.show(geo.getCenter());
        bnWindowsList.push(windowOne);
      }
    }
    /**
     * 创建弹窗数据
     */
    function createWindowTable(row) {
      let html = "";
      html += "<table class='tableClass' cellspacing='0' align='center'>";
      html += "<tr>";
      html += "<td class='td1 right-td' ><div class='div1'>序列号</div></td>";
      html += "<td class='td2 left-td'><div class='div2'style='word-break:break-all;'>" + row.serialNumber + "</div></td>";
      html += "</tr>";
      html += "<tr>";
      html += "<td class='td2 right-td' ><div class='div1'>区域</div></td>";
      html += "<td class='td3 left-td'><div class='div2'style='word-break:break-all;'>" + row.areaName + "</div></td>";
      html += "</tr>";
      html += "<tr>";
      html += "<td class='td1 right-td' ><div class='div1'>停航日期</div></td>";
      html += "<td class='td2 left-td'><div class='div2' style='word-break:break-all;'>" + row.day + "</div></td>";
      html += "</tr>";
      html += "<tr>";
      html += "<td class='td2 right-td' ><div class='div1'>停航时间</div></td>";
      html += "<td class='td3 left-td'><div class='div2' style='word-break:break-all;'>" + row.time + "</div></td>";
      html += "</tr>";
      html += "<tr>";
      html += "<td class='td1 right-td' ><div class='div1'>申请原因</div></td>";
      html += "<td class='td2 left-td'><div class='div2'style='word-break:break-all;'>" + row.applyReason + "</div></td>";
      html += "</tr>";
      html += "<tr>";
      html += "<td class='td2 right-td' ><div class='div1'>状态</div></td>";
      html += "<td class='td3 left-td'><div class='div2'style='word-break:break-all;'>" + row.status + "</div></td>";
      html += "</tr>";
      html += "</table>";
      return html;
    }
    /**
     * 绑定监听事件
     */
    function getMonitor() {
      // console.log('getMonitor');
      let ids = layers;
      for (let i = 0; i < ids.length; i++) {
        mapObj.bindEvent(ids[i], 'click', function (param) {
          window.parent["layerClick"](param);

          //添加高亮
          let polygonPoint = new BNMap.Polygon(param.target.getGeometries()[0].getCoordinates());
          polygonPoint.setSymbol({
            'polygonFill': "#ffffff",
            'polygonOpacity': 0.5,
            'lineColor': '#2C7AD6',
            'lineWidth': 2,
            'lineJoin': 'round', //miter, round, bevel
            'lineCap': 'round', //butt, round, square
          });
          lightLayer.clear();
          lightLayer.addGeometry(polygonPoint);
          addMarker([param.coordinate.x,
          param.coordinate.y]);
        });
      }
    }
    /**
     * 绑定监听事件
     */
     function getDrawMonitor(param) {
        if (isOpenDrawMonitor) {
          window.parent["drawMonitor"](param);
        }
    }
    /**
     * 开启绘画图层监听事件
     */
    function openDrawMonitor() {
      isOpenDrawMonitor = true;
    }
    /**
     * 开启绘画图层监听事件
     */
     function openGeoMonitor() {
      isOpenGeoMonitor = true;
    }
    /**
     * 需要加载的图层
     * @param geos - 所有图层
     */
    function setGeomtrys(geos) {
      let allGeo = [];
      let list = geos;
      for (let i = 0; i < list.length; i++) {
        for (let j = 0; j < list[i].geomtryLine.length; j++) {
          allGeo.push(list[i].geomtryLine[j]);
        }
        allGeo.push(list[i].geomtry);
      }
      geometryExtent = allGeo;
      if (bnmap) {
        addDrawLayer(geometryExtent);
      }
    }
    /**
     * 清楚所有高亮图层
     */
    function clearLight() {
      lightLayer.clear();
    }
    /**
     * 要素图层显示高亮图层
     */
    function showLightGeo(item) {
      let ids = layers;
      for (let i = 0; i < ids.length; i++) {
        let layer = bnmap.getLayer(ids[i]);
        let geos = layer._geoList;
        for (let j = 0; j < geos.length; j++) {
          if (geos[j].properties.resource_c == item.resourceC) {
            //添加高亮
            let polygonPoint = new BNMap.Polygon(geos[j].getGeometries()[0].getCoordinates());
            polygonPoint.setSymbol({
              'polygonFill': "#ffffff",
              'polygonOpacity': 0.5,
              'lineColor': '#2C7AD6',
              'lineWidth': 2,
              'lineJoin': 'round', //miter, round, bevel
              'lineCap': 'round', //butt, round, square
            });
            lightLayer.clear();
            lightLayer.addGeometry(polygonPoint);
            addMarker([item.x, item.y]);
          }
        }
      }
    }
    /**
     * 相交区域判断
     */
    function isIntersect(geo1, geo2) {
      let geometry1 = new BNMap.Geometry.fromJSON(JSON.parse(geo1));
      let geometry2 = new BNMap.Geometry.fromJSON(JSON.parse(geo2));
      let extent1 = geometry1.toGeoJSON();
      let extent2 = geometry2.toGeoJSON();
      let coors1 = extent1.geometry.coordinates;
      let collection1 = BNMap.turf.polygon(coors1);
      let coors2 = extent2.geometry.coordinates;
      if (coors2[0].length == 3) {
        return false;
      }
      let collection2 = BNMap.turf.polygon(coors2);
      return BNMap.turf.turf.booleanOverlap(collection1, collection2);
    }

    function addMarker(point) {
      // let layer = new BNMap.VectorLayer('vector').addTo(mapObj._innerMap);
      // lightLayer.clear();
      var marker1 = new BNMap.Marker(
        point,
        {
          'symbol': {
            'markerFile': 'red.png',
            'markerWidth': 28,
            'markerHeight': 40,
            'markerDx': 0,
            'markerDy': 0,
            'markerOpacity': 1
          }
        }
      ).addTo(lightLayer);
    }

    // 添加geo
    function addGeo(jsonObj) {
      return new BNMap.Geometry.fromJSON(jsonObj);
    }

    /**
     * 图层交叉验证，判断不能对同一个区域录入相同时间的不同施工项目
     */
     function checkLayer2(geo) {
      let isPass = false;
      let layerList = tempLayer.getGeometries();
      console.log(layerList)
      let index1 = geo.toGeoJSON();
      let coors = index1.geometry.coordinates;
      let collection = BNMap.turf.polygon(coors, { name: 'poly' });
      for (let i = 0; i < layerList.length; i++) {
        if (layerList[i].type == "Polygon") {
          let index2 = layerList[i].toGeoJSON();
          let coors2 = index2.geometry.coordinates;
          let collection2 = BNMap.turf.polygon(coors2, { name: 'poly' });
          if (BNMap.turf.turf.booleanOverlap(collection, collection2)) {
            isPass = true;
          }
          if (BNMap.turf.turf.booleanContains(collection, collection2) || BNMap.turf.turf.booleanContains(collection2, collection)) {
            isPass = true;
          }
          // if (BNMap.turf.turf.booleanEqual(collection, collection2)) {
          //   isPass = true;
          // }
        }
      }
      return isPass;
    }
  </script>
</body>

</html>
